package com.yh.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

/**
 * 
 * <pre>
 * - 过滤器Filter 实现Filter接口
 * - xml中的配置与Servlet差不多，只是将Servlet改成Filter;也可在类前些注解@WebFilter
 * ClassName : com.yh.filter.MyFilter
 * @author 湛锋
 * Date : 2020年8月6日 下午6:59:58
 * </pre>
 *
 */

//@WebFilter("/*")
public class MyFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		System.out.println("MyFilter 开始" + req.getRequestURI());
		chain.doFilter(request, response);
		System.out.println("MyFilter 结束");
	}

	@Override
	public void destroy() {
		
	}

}
